Skip to content

Conversation

manerlan
Copy link
Member

Closes #66 .

The typing tests in SearchPage.test.tsx used real time: user.type paused between key presses, and on a busy machine a pause could be longer than the 300 ms debounce, which sent an extra search. «shows all wines again when the field is cleared» also waited for the debounce with waitFor, which could time out.

  • The typing tests use vi.useFakeTimers({ shouldAdvanceTime: true }) and userEvent.setup({ delay: null }), and the test moves the clock past the debounce itself (pause()). A comment explains why all three are needed.
  • SEARCH_DEBOUNCE_MS is exported from useSearchText, so the tests use the same value as the code.
  • The tests that waited 400 ms of real time now move the fake clock instead.
  • Second commit: all test names in the file are in English, as agreed in the conventions. The Norwegian texts the tests look for are unchanged.

Tested: the whole suite 5 times in a row with no failures, and npm run check.
npm run check fails on ESLint in AuthForm.tsx. That error is already on main (from #65) and is fixed in a separate PR for issue (#76). Prettier fails on line endings, the known issue.

Wait to merge until issue #76 is merged

@manerlan manerlan requested a review from a team as a code owner November 17, 2026 18:53
@manerlan manerlan linked an issue Nov 17, 2026 that may be closed by this pull request
Copy link
Member

@williasc williasc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix. The reasoning in the comment is clear, and the tests are stable for me: the file 10 times in a row and the full suite 9 times under load, all green. (I couldn't get the old version to fail on my machine either, so I can't confirm the before/after.)

@williasc williasc merged commit cec1c61 into main Nov 17, 2026
@williasc williasc deleted the 66-debounce-test-fix branch November 17, 2026 20:50
@manerlan
Copy link
Member Author

npm run check now passes all checks, after #79 and #80 were merged into main

Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make the search debounce test independent of machine speed
2 participants